export const getQuery = function (url) {
    let queryStringList = url.split("?")[1] && url.split("?")[1].split("&") || []
    let result = {}
    queryStringList.map(item => {
        let key = item.split("=")[0]
        let value = item.split("=")[1]
        result[key] = value
    })
    return result

}
export const copyImg= function (elementId,url,callback) {
    if (document.body.createControlRange) { //IE 11 需要有个img标签
        var controlRange;
        var imgs = document.getElementById(elementId);
        imgs.onload = function () {
            controlRange = document.body.createControlRange();
            imgs.contentEditable = 'true';
            controlRange.addElement(imgs);
            try {
                var successful = controlRange.execCommand('copy');
                var msg = successful ? 'successful' : 'unsuccessful';
                console.log('Copying text command was ' + msg);
            } catch (err) {
                console.log(err);
            }
        }
        imgs.src =url;
    }
    else{
        var canvas = document.createElement("canvas")
        var image = document.getElementById(elementId)
        canvas.height=image.width
        canvas.width=image.width
        var context = canvas.getContext('2d');
        image.crossOrigin = "Anonymous"
        image.src=url
        image.onload = function () {
            context.drawImage(image, 0, 0, image.width, image.width)
            canvas.toBlob(blob => {
                navigator.clipboard.write([new ClipboardItem({'image/png': blob })])
                callback("复制成功")
            })
        }
    }
  
}